/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ia_project;

import Entites.Espece;
import Vue.Monde;
import com.trolltech.qt.core.QPoint;
import com.trolltech.qt.core.Qt.Orientation;
import com.trolltech.qt.gui.QApplication;
import com.trolltech.qt.gui.QComboBox;
import com.trolltech.qt.gui.QDesktopWidget;
import com.trolltech.qt.gui.QGridLayout;
import com.trolltech.qt.gui.QGroupBox;
import com.trolltech.qt.gui.QHBoxLayout;
import com.trolltech.qt.gui.QIcon;
import com.trolltech.qt.gui.QLCDNumber;
import com.trolltech.qt.gui.QLabel;
import com.trolltech.qt.gui.QProgressBar;
import com.trolltech.qt.gui.QSlider;
import com.trolltech.qt.gui.QTextEdit;
import com.trolltech.qt.gui.QVBoxLayout;
import com.trolltech.qt.gui.QWidget;

/**
 *
 * @author JeanW
 */
public class WorldWindow extends QWidget {

    QGroupBox infosBox;
    QGroupBox infosBoxP;
    QComboBox listBox;
    QTextEdit textBox;
    QLabel textLabel;
    QLabel textLabelP;
    QLabel textLabelT;
    QLabel textLabelM;
    QLabel textLabelE;
    QLCDNumber lcdSpeed;
    QProgressBar test;
    Monde env;
    QLabel nom, sexe, fitness, faim, agress, soif, taille, humeur, negociation, resist, force, patience, poids, vie;
    QProgressBar agressBar, fitnessBar, faimBar, soifBar, tailleBar, humeurBar, negociationBar, resistBar, forceBar, patienceBar, poidsBar, vieBar;

    public WorldWindow(int nbPopulation) {
        /*************configuration de la fenêtre*******************/
        setWindowTitle("World"); //titre de la fenêtre
        setWindowIcon(new QIcon("./img/logo.png"));//icone de la fenêtre
        resize(1200, 684);
        /******************************************************************************/
        /*************centrer la fenetre à l'ecran*************************************/
        QDesktopWidget widget = QApplication.desktop();
        int desktop_width = widget.width();
        int desktop_height = widget.height();
        int x = desktop_width / 2 - width() / 2;
        int y = desktop_height / 2 - height() / 2 - 25;
        move(new QPoint(x, y));
        /********************************************************************************/
        /***********************Intégration de l'environnement***************************/
        QHBoxLayout layout = new QHBoxLayout();

        env = new Monde(nbPopulation);
        layout.addWidget(env);
        infosBoxP = new QGroupBox("Informations sur la population");
        textLabelP = new QLabel("Population : " + env.getPopulation().getNombreAll());
        textLabelT = new QLabel("Troll : " + env.getPopulation().getNombreTroll());
        textLabelM = new QLabel("Mage : " + env.getPopulation().getNombreMagicien());
        textLabelE = new QLabel("Elfe : " + env.getPopulation().getNombreElfe());
        nom = new QLabel("Nom : ");
        sexe = new QLabel("Sexe : ");
        agress = new QLabel("Agressivité : ");
        humeur = new QLabel("Humeur : ");
        negociation = new QLabel("Négociation : ");
        patience = new QLabel("Patience : ");
        faim = new QLabel("Faim : ");
        fitness = new QLabel("Fitness : ");
        force = new QLabel("Force : ");
        poids = new QLabel("Poids : ");
        resist = new QLabel("Resistance : ");
        soif = new QLabel("Soif : ");
        taille = new QLabel("Taille : ");
        vie = new QLabel("Vie : ");
        agressBar = new QProgressBar();
        humeurBar = new QProgressBar();
        negociationBar = new QProgressBar();
        patienceBar = new QProgressBar();
        faimBar = new QProgressBar();
        fitnessBar = new QProgressBar();
        forceBar = new QProgressBar();
        poidsBar = new QProgressBar();
        resistBar = new QProgressBar();
        soifBar = new QProgressBar();
        tailleBar = new QProgressBar();
        vieBar = new QProgressBar();
        infosBoxP.setMaximumSize(200, 100);
        QVBoxLayout regroupInfo = new QVBoxLayout();

        QVBoxLayout InfosPLayout = new QVBoxLayout();
        InfosPLayout.addWidget(textLabelP);
        InfosPLayout.addWidget(textLabelT);
        InfosPLayout.addWidget(textLabelM);
        InfosPLayout.addWidget(textLabelE);
        infosBoxP.setLayout(InfosPLayout);
        regroupInfo.addWidget(infosBoxP);
        //layout.addWidget();
        //setLayout(layout);

        infosBox = new QGroupBox("Informations sur les espèces");
        infosBox.setMaximumWidth(600);
        textLabel = new QLabel("Espèce");
        listBox = new QComboBox();

        listBox.addItems(env.getPopulation().getAllNom());

        // textBox = new QTextEdit();


        // textBox.setMaximumWidth(200);
        //textBox.setReadOnly(true);
        getIdList(listBox.currentIndex());
        listBox.currentIndexChanged.connect(this, "getIdList(int)");
        QGridLayout InfosLayout = new QGridLayout();
        InfosLayout.addWidget(textLabel, 0, 0);
        InfosLayout.addWidget(listBox, 0, 1, 1, 6);
        InfosLayout.addWidget(nom, 1, 0, 2, 6);
        InfosLayout.addWidget(sexe, 1, 0, 3, 6);
        InfosLayout.addWidget(agress, 1, 0, 4, 6);
        InfosLayout.addWidget(agressBar, 1, 2, 4, 6);

        InfosLayout.addWidget(humeur, 1, 0, 5, 6);
        InfosLayout.addWidget(humeurBar, 1, 2, 5, 6);

        InfosLayout.addWidget(fitness, 1, 0, 6, 6);
        InfosLayout.addWidget(fitnessBar, 1, 2, 6, 6);

        InfosLayout.addWidget(taille, 1, 0, 7, 6);
        InfosLayout.addWidget(tailleBar, 1, 2, 7, 6);

        InfosLayout.addWidget(soif, 1, 0, 8, 6);
        InfosLayout.addWidget(soifBar, 1, 2, 8, 6);

        InfosLayout.addWidget(patience, 1, 0, 9, 6);
        InfosLayout.addWidget(patienceBar, 1, 2, 9, 6);

        InfosLayout.addWidget(faim, 1, 0, 10, 6);
        InfosLayout.addWidget(faimBar, 1, 2, 10, 6);

        InfosLayout.addWidget(resist, 1, 0, 11, 6);
        InfosLayout.addWidget(resistBar, 1, 2, 11, 6);

        InfosLayout.addWidget(force, 1, 0, 12, 6);
        InfosLayout.addWidget(forceBar, 1, 2, 12, 6);

        InfosLayout.addWidget(poids, 1, 0, 13, 6);
        InfosLayout.addWidget(poidsBar, 1, 2, 13, 6);

        InfosLayout.addWidget(vie, 1, 0, 14, 6);
        InfosLayout.addWidget(vieBar, 1, 2, 14, 6);

        infosBox.setLayout(InfosLayout);
        regroupInfo.addWidget(infosBox);



        QGroupBox speed = new QGroupBox("Vitesse");
        lcdSpeed = new QLCDNumber(3);
        lcdSpeed.setFixedHeight(30);
        lcdSpeed.setSegmentStyle(QLCDNumber.SegmentStyle.Flat);

        QSlider slider = new QSlider(Orientation.Horizontal);
        slider.setRange(0, 1000);
        slider.setValue(0);
        slider.valueChanged.connect(lcdSpeed, "display(int)");
        slider.valueChanged.connect(env, "changeVitesse(int)");
        QVBoxLayout vlayout = new QVBoxLayout();
        vlayout.addWidget(lcdSpeed);
        vlayout.addWidget(slider);
        speed.setLayout(vlayout);
        //regroupInfo.addWidget(speed);
        //regroupInfo.addSpacing(100);
        layout.addLayout(regroupInfo);
        setLayout(layout);

        env.mondeChange.connect(this, "updateWindow()");

    }

    public void updateWindow() {
        //System.out.println("Population : " + env.getPopulation().getNombreAll());
        textLabelP.setText("Population : " + env.getPopulation().getNombreAll());
        textLabelT.setText("Troll : " + env.getPopulation().getNombreTroll());
        textLabelM.setText("Mage : " + env.getPopulation().getNombreMagicien());
        textLabelE.setText("Elfe : " + env.getPopulation().getNombreElfe());
        listBox.clear();
        listBox.addItems(env.getPopulation().getAllNom());
        vieBar.setValue(Integer.parseInt(env.getPopulation().getInformationEspece(listBox.currentIndex()).get(13).toString()));
    }

    public void getIdList(int es) {
        for (int i = 0; i < env.getPopulation().getInformationEspece(es).size(); i++) {
            switch (i) {
                case 0:
                    nom.setText("Nom : " + env.getPopulation().getInformationEspece(es).get(i));
                    break;
                case 1:
                    sexe.setText("Sexe : " + env.getPopulation().getInformationEspece(es).get(i));
                    break;
                case 2:
                    agressBar.setFixedSize(110, 10);
                    agressBar.setValue(Integer.parseInt(env.getPopulation().getInformationEspece(es).get(i).toString()));
                    break;
                case 3:
                    humeurBar.setFixedSize(110, 10);
                    humeurBar.setValue(Integer.parseInt(env.getPopulation().getInformationEspece(es).get(i).toString()));
                    break;
                case 4:
                    negociationBar.setFixedSize(110, 10);
                    negociationBar.setValue(Integer.parseInt(env.getPopulation().getInformationEspece(es).get(i).toString()));
                    break;
                case 5:
                    patienceBar.setFixedSize(110, 10);
                    patienceBar.setValue(Integer.parseInt(env.getPopulation().getInformationEspece(es).get(i).toString()));
                    break;
                case 6:
                    faimBar.setFixedSize(110, 10);
                    faimBar.setValue(Integer.parseInt(env.getPopulation().getInformationEspece(es).get(i).toString()));
                    break;
                case 7:
                    fitnessBar.setFixedSize(110, 10);
                    fitnessBar.setValue(Integer.parseInt(env.getPopulation().getInformationEspece(es).get(i).toString()));
                    break;
                case 8:
                    forceBar.setFixedSize(110, 10);
                    forceBar.setValue(Integer.parseInt(env.getPopulation().getInformationEspece(es).get(i).toString()));
                    break;
                case 9:
                    poidsBar.setFixedSize(110, 10);
                    poidsBar.setValue(Integer.parseInt(env.getPopulation().getInformationEspece(es).get(i).toString()));
                    break;
                case 10:
                    resistBar.setFixedSize(110, 10);
                    resistBar.setValue(Integer.parseInt(env.getPopulation().getInformationEspece(es).get(i).toString()));
                    break;
                case 11:
                    soifBar.setFixedSize(110, 10);
                    soifBar.setValue(Integer.parseInt(env.getPopulation().getInformationEspece(es).get(i).toString()));
                    break;
                case 12:
                    tailleBar.setFixedSize(110, 10);
                    tailleBar.setValue(Integer.parseInt(env.getPopulation().getInformationEspece(es).get(i).toString()));
                    break;
                case 13:
                    vieBar.setMaximum(Integer.parseInt(env.getPopulation().getInformationEspece(es).get(i+1).toString()));
                    vieBar.setFixedSize(110, 10);
                    vieBar.setValue(Integer.parseInt(env.getPopulation().getInformationEspece(es).get(i).toString()));
                    break;
            }
        }
    }
}
